using System;

namespace TomNet.Attributes
{
    public class GuidString : BaseAttribute
    {
        public override string Error
        {
            get => base.Error ?? "不是有效的GUID字符串";
            set => base.Error = value;
        }

        public override bool Validate(object value)
        {
            var str = (string)value;
            if (String.IsNullOrEmpty(str) || str.Length != 36) { return false; }
            string[] arr = str.Split('-');
            if (arr.Length != 5) { return false; }
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    char a = arr[i][j];
                    if (!((a >= 48 && a <= 57) || (a >= 65 && a <= 90) || (a >= 97 && a <= 122)))
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}